package cn.lxs.web.servletContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ContextDemo1")
public class ContextDemo1 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //ServletContext的获取
        //通过request来获取
        ServletContext context1 = req.getServletContext();
        //通过  Http来获取
        ServletContext context2 = this.getServletContext();
        //比较一下
        System.out.println(context1==context2);
        //true
        System.out.println(context1);
        //org.apache.catalina.core.ApplicationContextFacade@376ea80b
        System.out.println(context2);
    }
}
